package com.bzkj.basicinfo.jobTask;

import com.bzkj.basicinfo.service.warehouse.IPdaBillsListService;
import com.bzkj.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("jobTask")
public class JobTask
{
    private static final Logger log = LoggerFactory.getLogger(JobTask.class);

    @Autowired
    private IPdaBillsListService pdaBillsListService;

    /**
     * 定时查询当天出库单据
     * 每天定时执行，查询当天的AO（出库单）类型单据
     */
    public void queryTodayOutboundBills(String billsType)
    {
        log.info("开始执行定时任务：查询当天出库单据");

        try
        {
            // 调用服务方法查询当天出库单据
            Map<String, Object> result = pdaBillsListService.queryTodayOutboundBills(billsType);

            if (result != null && (Boolean) result.get("success"))
            {
                String queryDate = (String) result.get("queryDate");
                String queryRange = (String) result.get("queryRange");
                String message = (String) result.get("message");
                log.info("定时任务执行成功：{}", message);
                log.info("查询日期：{}，查询范围：{}，单据类型：AO（出库单）", queryDate, queryRange);
            }
            else
            {
                String errorMessage = result != null ? (String) result.get("message") : "未知错误";
                log.error("定时任务执行失败：{}", errorMessage);
            }
        }
        catch (Exception e)
        {
            log.error("执行定时查询当天出库单据任务时发生异常", e);
        }

        log.info("定时任务执行完成：查询当天出库单据");
    }
}
